var dealerNawSavedSearch = 'customsearch_at_dealer_xml_naw';

function updateCustomer(rec_type, rec_id){
    var customer = nlapiLoadRecord(rec_type, rec_id);
    
    nlapiLogExecution('debug', 'Customer Id: ' + customer.getId(), 'Saving Customer');
    nlapiSubmitRecord(customer);
    nlapiLogExecution('debug', 'Customer Id: ' + customer.getId(), 'Customer Saved');
}

function loopCustomers(searchType, savedSearch, func){
    var lastCustomerId = 0;
    var finished = false;
    
    while (!finished) {
        var filter = new nlobjSearchFilter('formulanumeric', null, 'greaterthan', lastCustomerId);
        filter.setFormula('TO_NUMBER({entityid})');
        var customers = nlapiSearchRecord(searchType, savedSearch, filter, null);
        if (customers != null && customers.length > 0) {
            for (var i = 0; i < customers.length; i++) {
                var customer = customers[i];
                var id = customer.getValue('entityid');
                
                func(customer, id);
                
                lastCustomerId = customer.getValue('formulanumeric');
            }
        }
        else {
            finished = true;
        }
    }
}
